package LeetCodeHot100TopInterview;

public class Q011_MaxWaterArea {
    //乘最多水的容器
    //找出其中的两条线，使得它们与 x 轴共同构成的容器可以容纳最多的水
    public int maxArea(int[] height) {
        if (height == null || height.length == 0){
            return 0;
        }
        int left = 0;
        int right = height.length - 1;
        int ans = Integer.MIN_VALUE;
        while (left != right){
            //两边哪边短 能 cover 住的就这么多
            int h = Math.min(height[left], height[right]);
            ans = Math.max(h * (right - left), ans);
            if (height[left] < height[right]){
                left ++;
            }else {
                right --;
            }

        }
        return ans;
    }

    public static void main(String[] args) {
        Q011_MaxWaterArea fun = new Q011_MaxWaterArea();
        System.out.println(fun.maxArea(new int[]{2, 3, 4, 5, 18, 17, 6}));
    }
}
